package com.juku2024.juku.adapter

import android.text.TextUtils
import android.widget.ImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.juku2024.juku.R
import com.juku2024.juku.model.CommonModel
import com.juku2024.juku.tools.ImageUtils

class ThemeDetailItemAdapter(data: ArrayList<CommonModel>): BaseQuickAdapter<CommonModel, BaseViewHolder>(R.layout.item_theme_detail_list, data) {

    // 是否显示角标
    var isShowIcon = false

    override fun convert(holder: BaseViewHolder, item: CommonModel) {
        val iv = holder.getView<ImageView>(R.id.iv_theme)
        ImageUtils.loadImageV(iv, item.pic)

        if (isShowIcon) {
            when (holder.layoutPosition){
                0 -> {
                    holder.setText(R.id.icon, "")
                    holder.setBackgroundResource(R.id.icon, R.drawable.ic_ranking_1)
                }
                1 -> {
                    holder.setText(R.id.icon, "")
                    holder.setBackgroundResource(R.id.icon, R.drawable.ic_ranking_2)
                }
                2 -> {
                    holder.setText(R.id.icon, "")
                    holder.setBackgroundResource(R.id.icon, R.drawable.ic_ranking_3)
                }
                else -> {
                    holder.setText(R.id.icon, (holder.layoutPosition + 1).toString())
                    holder.setBackgroundResource(R.id.icon, R.drawable.shape_ranking)
                }
            }
        }

        holder.setText(R.id.tvTitle, item.name)
            .setText(R.id.tvActor, "主演：" + item.actor)
            .setText(R.id.tvDirector, "导演：" + item.director)

        val tagBuilder = StringBuilder()
        if (!TextUtils.isEmpty(item.score)) {
            tagBuilder.append(item.score)
            tagBuilder.append("分")
        }
        if (!TextUtils.isEmpty(item.year)) {
            if (tagBuilder.isNotEmpty()) {
                tagBuilder.append("·")
            }
            tagBuilder.append(item.year)
        }
        holder.setText(R.id.tvTag, tagBuilder)


    }
}